package service

import (
	"log"
	"prometheus_import_consul/global"
	"prometheus_import_consul/tools"
)

// 定义用于解析YAML的结构体
type IcmpInfo map[string][]string

func Icmp() {

	var results IcmpInfo
	err := tools.ReadJSONFile(global.Config.JsonFile.Hostjson_Path, &results)
	if err != nil {
		log.Fatalf("Error reading adn parsing JSON file: %s,error: %v\n", global.Config.JsonFile.Hostjson_Path, err)
	}
	log.Printf("Success reading and parsing JSON file: %s\n", global.Config.JsonFile.Hostjson_Path)

	for icmpIP, svc_info := range results {
		if len(svc_info) >= 3 {
			tools.Add_Icmp(icmpIP, svc_info[0], global.Config.Consul.ServiceName[1], svc_info[2])
		}
	}
}
